#ifndef PIKA_HAL_EX_H
#define PIKA_HAL_EX_H

#include "pika_hal.h"
#include "PikaObj.h"

// #define PIKA_HAL_SIMPLE_DEQUE 

#ifdef PIKA_HAL_SIMPLE_DEQUE

// 定义循环指针队列的结构体
typedef struct pika_hal_deque {
    void** buffer;  // 存储元素的缓冲区
    size_t head;    // 队头指针
    size_t tail;    // 队尾指针
    size_t count;   // 当前元素数量
    size_t capacity; // 缓冲区容量
#if PIKA_HAL_CIRCULAR_QUEUE_MUTEX_ENABLE
    pika_platform_thread_mutex_t mutex;  // 互斥锁
#endif
} pika_hal_deque;

// 创建一个新的循环指针队列
pika_hal_deque* pika_hal_deque_create(size_t capacity);

// 向队列中添加一个元素
int pika_hal_deque_appendHead(pika_hal_deque* cb, void* value);
int pika_hal_deque_appendTail(pika_hal_deque* cb, void* value);
// 从队列中移除一个元素
int pika_hal_deque_popHead(pika_hal_deque* cb, void** value);
int pika_hal_deque_popTail(pika_hal_deque* cb, void** value);


// 销毁队列并释放相关资源
int pika_hal_deque_deinit(pika_hal_deque* cb);

// 获取队列中的元素数量
size_t pika_hal_deque_getCount(pika_hal_deque* cb);

// 检查队列是否为空
int pika_hal_deque_isEmpty(pika_hal_deque* cb);

// 检查队列是否已满
int pika_hal_deque_isFull(pika_hal_deque* cb);



#else
// 定义双向链表节点
typedef struct _Node {
    void* data;
    struct _Node* prev;
    struct _Node* next;
} Node;

// 定义双端队列结构
typedef struct _Deque {
    Node* head;  // 指向队首
    Node* tail;  // 指向队尾
    size_t count;  // 队列中的元素数量
    size_t maxlen;  // 队列的最大容量
#if PIKA_HAL_CIRCULAR_QUEUE_MUTEX_ENABLE
    pika_platform_thread_mutex_t mutex;  // 互斥锁
#endif
} pika_hal_deque;

// 创建一个新的双端队列
pika_hal_deque* pika_hal_deque_create(size_t capacity);

// 销毁双端队列
int pika_hal_deque_deinit(pika_hal_deque* deque);

// 在队尾添加元素
int pika_hal_deque_appendTail(pika_hal_deque* deque, void* value);

// 在队首添加元素
int pika_hal_deque_appendHead(pika_hal_deque* deque, void* value);

// 从队首移除元素
int pika_hal_deque_popHead(pika_hal_deque* deque, void** value);

// 从队尾移除元素
int pika_hal_deque_popTail(pika_hal_deque* deque, void** value);

// 查看队首元素
int pika_hal_deque_peekHead(pika_hal_deque* deque, void** value);

// 查看队尾元素
int pika_hal_deque_peekTail(pika_hal_deque* deque, void** value);

// 获取队列中的元素数量
size_t pika_hal_deque_getCount(pika_hal_deque* deque);

// 检查队列是否为空
int pika_hal_deque_isEmpty(pika_hal_deque* deque);

// 检查队列是否已满
int pika_hal_deque_isFull(pika_hal_deque* deque);
#endif // PIKA_HAL_SIMPLE_DEQUE


#endif  // PIKA_HAL_CIRCULAR_PTR_QUEUE_H